package com.yunhe.option.repository.data;

import com.yunhe.option.domain.data.CostPrice;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CostPriceRepository extends Neo4jRepository<CostPrice, Long> {
    @Query("start c=Node({id}) match (c)-[]-(s:SeasonPrice)-[]-(d:SeasonPriceDetail) detach delete d, s, c")
    void deleteCostPrice(@Param("id") Long id);

    @Query("start c=Node({id}) match (v:VoltageLevel) where v.code in {voltageLevelCodeList} create (c)-[:VOLTAGE_LEVEL_OF]->(v)")
    void bindVoltageLevel(@Param("id") Long id, @Param("voltageLevelCodeList") List<Long> voltageLevelCodeList);

    @Query("start c=Node({id}), a=Node({areaId}) create (c)-[:AREA_OF]->(a)")
    void bindArea(@Param("id") Long id, @Param("areaId") Long areaId);

    @Query("start s=Node({stationId}), p=Node({costPriceId}) create (s)-[:HAS_COST_PRICE]->(p)")
    void bindStation(@Param("stationId") Long stationId, @Param("costPriceId") Long costPriceId);

    @Query("match (c:CostPrice) where c.title = {title} return c")
    CostPrice findByTitle(@Param("title") String title);

    @Query("start s=Node({id}) match (s)-[]-(cp:CostPrice) return cp")
    Iterable<CostPrice> findByStationId(@Param("id") Long id);
}
